//
//  QXGuideVC.m
//  QXWeibo2
//
//  Created by QinXin on 15/7/1.
//  Copyright © 2015年 labi3285_Lab. All rights reserved.
//

#import "QXGuideVC.h"
#import "QXGuideCell.h"

@interface QXGuideVC () <UIScrollViewDelegate>

@property (nonatomic, strong) UICollectionViewFlowLayout *flowLayout;

@property (nonatomic, strong) NSArray *data;

@end

@implementation QXGuideVC

- (NSArray *)data {
    if (!_data) {
        _data = @[
                  @"new_feature_1",
                  @"new_feature_2",
                  @"new_feature_3",
                  @"new_feature_4",
                  ];
    }
    return _data;
}

- (UICollectionViewFlowLayout *)flowLayout {
    if (!_flowLayout) {
        _flowLayout = [[UICollectionViewFlowLayout alloc] init];
        _flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        _flowLayout.minimumInteritemSpacing = 0;
        _flowLayout.minimumLineSpacing = 0;
    }
    return _flowLayout;
}

- (instancetype)init {
    
    if (self = [super initWithCollectionViewLayout: self.flowLayout]) {
        [self.collectionView registerClass:[QXGuideCell class] forCellWithReuseIdentifier:@"guide_cell"];
        self.view.backgroundColor = [UIColor whiteColor];
        
        self.collectionView.pagingEnabled = YES;
        self.collectionView.bounces = NO;
        self.collectionView.showsHorizontalScrollIndicator = NO;
    }
    return self;
}

- (void)viewWillLayoutSubviews {
    self.flowLayout.itemSize = [UIScreen mainScreen].bounds.size;
}



- (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.data.count;
}

- (UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
    QXGuideCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"guide_cell" forIndexPath:indexPath];
    cell.picName = self.data[indexPath.row];
    return cell;
}


#pragma mark - UIScrollViewDelegate
- (void)collectionView:(nonnull UICollectionView *)collectionView didEndDisplayingCell:(nonnull UICollectionViewCell *)cell forItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
    
    if (collectionView.indexPathsForVisibleItems.lastObject.item == self.data.count - 1) {
        QXGuideCell *cell = (QXGuideCell *)[collectionView cellForItemAtIndexPath: [NSIndexPath indexPathForItem:self.data.count - 1 inSection:0]];
        [cell showBtn];
    }
 
}

@end
